<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left" />
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          v-if="tableColumns.length>0"
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          style="width: 99.9%"
        >
          <el-table-column type="index" label="序号" align="center" />
          <Column v-for="(column,index) in tableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { detailsList as list } from '@/api/superManage/iotManage/iotUpload'
import { list as getCompany } from '@/api/superManage/tenantManage'
export default {
  name: 'Index',
  props: {
    layerid: {},
    row: {}
  },
  data() {
    return {
      loading: true,
      pageId: '设备查询', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'deviceId', label: 'IOT编码' },
        { prop: 'hostName', label: 'IOT名称' },
        { prop: 'iotType', label: 'IOT类型' },
        { prop: 'customerName', label: '客户归属' },
        { prop: 'deviceName', label: '关联设备' },
        { prop: 'realName', label: '操作人员' },
        { prop: 'createTime', label: '操作时间' }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'deviceId', label: 'IOT编码', type: 'input' },
        { prop: 'hostName', label: 'IOT名称', type: 'input' },
        { prop: 'iotType', label: 'IOT类型', type: 'input' },
        { prop: 'customerId', label: '客户归属', type: 'select', optionsName: 'customerOptions' },
        { prop: 'deviceName', label: '关联设备', type: 'input' },
        { prop: 'realName', label: '操作人员', type: 'input' },
        { prop: 'createTime', label: '操作时间', type: 'time' }
      ],

      operationData: [ // 右上角的操作按钮
      ],

      customerOptions: []
    }
  },
  mounted() {
    getCompany().then(res => {
      const cacheData = []
      res.data.forEach(item => {
        cacheData.push({
          value: item.id,
          label: item.name
        })
      })
      this.customerOptions = cacheData
    })
  },
  methods: {
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    }

  }
}
</script>

<style lang="less" scoped>
.main_header{
  display: none;
  height: 0px;
}
.main_main{
  margin: 0;
  height: calc(100% - 50px);
}
</style>
